package com.xzz.treeBST;


/**
 * @author: hhz
 * @create: 2022-01-20 11:59
 **/
public class RecoverTree {
    public static void main(String[] args) {
        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(3);
        TreeNode node3 = new TreeNode(2);
        node1.setLeft(node2);
        node2.setRight(node3);
        recoverTree(node1);
    }
    static TreeNode num1 = null;
    static TreeNode num2 = null;
    static TreeNode preNum = new TreeNode(Integer.MIN_VALUE);
    public static void recoverTree(TreeNode root) {
        traverse(root);
    }

    public static void traverse(TreeNode node){
        if(null==node){
            return;
        }
        traverse(node.left);
        if(node.val<preNum.val){
            if(null==num1){
                num1 = preNum;
            }
            num2 = node;
        }
        preNum = node;
        traverse(node.right);
    }
}
